/*
 * Tezad - Classic puzzle game
 * Copyright 2009 Shayne Riley and Paul Maseberg
 *
 * Tezad is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tezad is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tezad.  If not, see <http://www.gnu.org/licenses/>
 * or write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * To contact the authors on questions or issues regarding the license,
 * you may send an email to <pezads at gmail dot com>
 */

#include "GameActions.h"

MovementAction::MovementAction(int actionType)
: mActionType(actionType)
{
    // TODO Make sure it is one of the commands.
}

MovementAction::~MovementAction() { /* Empty because there's nothing to do. */ }

void MovementAction::execute(CommandActions &actions) const
{
    switch (mActionType)
    {
    case MA_SHIFT_LEFT:
        actions.shiftLeft();
        break;
    case MA_SHIFT_RIGHT:
        actions.shiftRight();
        break;
    case MA_SOFT_DOWN:
        actions.softDown();
        break;
    case MA_HARD_DOWN:
        actions.hardDown();
        break;
    case MA_GRAVITY_DOWN:
        actions.gravityDown();
        break;
    case MA_SHIFT_UP:
        actions.shiftUp();
        break;
    case MA_ROTATE_CLOCKWISE:
        actions.rotateCW();
        break;
    case MA_ROTATE_COUNTERCLOCKWISE:
        actions.rotateCCW();
        break;
    default:
        throw 0; // hahahaha I'm so bad
        break;
    }
}

// SetMinoAction
SetMinoAction::SetMinoAction() { /* Empty */ }

SetMinoAction::~SetMinoAction() { /* Empty */ }

void SetMinoAction::execute(CommandActions &actions) const
{
    actions.setMino();
}

// NewMinoAction
NewMinoAction::NewMinoAction(int minoNum)
: mMinoNum(minoNum)
{
    // Should probably check for bound conditions here. Oh well.
}

NewMinoAction::~NewMinoAction() { /* Empty */ }

void NewMinoAction::execute(CommandActions &actions) const
{
    actions.newMino(mMinoNum);
}

// ClearRowsAction
ClearRowsAction::ClearRowsAction(const int rows[], int numRows)
: mNumRows(numRows)
{
    // Should check to make sure numRows is 0-3. Oh well.

    for (int i = 0; i < numRows && i < 4; ++i)
    {
        // Should check to make sure that the row is legal. Oh well.

        mRows[i] = rows[i];
    }
}

ClearRowsAction::~ClearRowsAction() { /* Empty */ }

void ClearRowsAction::execute(CommandActions &actions) const
{
    actions.clearRows(mRows, mNumRows);
}

// SpeedAction
SpeedAction::SpeedAction(int speed)
: mSpeed(speed)
{
    // Should check to make sure speed is 0-20. Oh well.
}

SpeedAction::~SpeedAction() { /* Empty */ }

void SpeedAction::execute(CommandActions &actions) const
{
    actions.setSpeed(mSpeed);
}

// InitGameAction
InitGameAction::InitGameAction(int width, int totalHeight, int hiddenHeight,
        int startRow, int startCol, int startSpeed)
: mWidth(width), mTotalHeight(totalHeight), mHiddenHeight(hiddenHeight),
mStartRow(startRow), mStartCol(startCol), mStartSpeed(startSpeed)
{
    // Should probably check this legality out.
}

InitGameAction::~InitGameAction() { /* Empty */ }

void InitGameAction::execute(CommandActions &actions) const
{
    actions.initGame(mWidth, mTotalHeight, mHiddenHeight, mStartRow, mStartCol,
            mStartSpeed);
}

//// SomeAction
//SomeAction::SpeedAction() { /* Empty */ }
//
//SomeAction::~SomeAction() { /* Empty */ }
//
//void SomeAction::execute(CommandActions &actions) const { /* Empty */ }
